home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / ops.h < prev    next >
C/C++ Source or Header  |  1997-07-20  |  4KB  |  132 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_ops_h)
  24. #define octave_ops_h 1
  25.  
  26. extern void install_ops (void);
  27.  
  28. #define INSTALL_UNOP(op, t, f) \
  29.   octave_value_typeinfo::register_unary_op \
  30.     (octave_value::op, t::static_type_id (), f);
  31.  
  32. #define INSTALL_BINOP(op, t1, t2, f) \
  33.   octave_value_typeinfo::register_binary_op \
  34.     (octave_value::op, t1::static_type_id (), t2::static_type_id (), f);
  35.  
  36. #define INSTALL_ASSIGNOP(t1, t2, f) \
  37.   octave_value_typeinfo::register_assign_op \
  38.     (t1::static_type_id (), t2::static_type_id (), f);
  39.  
  40. #define INSTALL_ASSIGNCONV(t1, t2, tr) \
  41.   octave_value_typeinfo::register_pref_assign_conv \
  42.     (t1::static_type_id (), t2::static_type_id (), tr::static_type_id ());
  43.  
  44. #define INSTALL_WIDENOP(t1, t2, f) \
  45.   octave_value_typeinfo::register_widening_op \
  46.     (t1::static_type_id (), t2::static_type_id (), f);
  47.  
  48. #define BOOL_OP1(xt, xn, get_x, yt, yn, get_y) \
  49.   xt xn = get_x; \
  50.   yt yn = get_y;
  51.  
  52. #define BOOL_OP2(x) \
  53.   int nr = x.rows (); \
  54.   int nc = x.columns ();
  55.  
  56. #define BOOL_OP3(test) \
  57.   Matrix retval (nr, nc); \
  58.   for (int j = 0; j < nc; j++) \
  59.     for (int i = 0; i < nr; i++) \
  60.       retval (i, j) = test; \
  61.   return retval;
  62.  
  63. #define SC_MX_BOOL_OP(st, sn, get_s, mt, mn, get_m, test, empty_result) \
  64.   do \
  65.     { \
  66.       BOOL_OP1 (st, sn, get_s, mt, mn, get_m) \
  67.       BOOL_OP2 (mn) \
  68.       if (nr == 0 || nc == 0) \
  69.         return empty_result; \
  70.       BOOL_OP3 (test) \
  71.     } \
  72.   while (0)
  73.  
  74. #define MX_SC_BOOL_OP(mt, mn, get_m, st, sn, get_s, test, empty_result) \
  75.   do \
  76.     { \
  77.       BOOL_OP1 (mt, mn, get_m, st, sn, get_s) \
  78.       BOOL_OP2 (mn) \
  79.       if (nr == 0 || nc == 0) \
  80.         return empty_result; \
  81.       BOOL_OP3 (test) \
  82.     } \
  83.   while (0)
  84.  
  85. #define MX_MX_BOOL_OP(m1t, m1n, get_m1, m2t, m2n, get_m2, test, op, \
  86.               one_empty_result, two_empty_result) \
  87.   do \
  88.     { \
  89.       BOOL_OP1 (m1t, m1n, get_m1, m2t, m2n, get_m2) \
  90.       int m1_nr = m1n.rows (); \
  91.       int m1_nc = m1n.cols (); \
  92.       int m2_nr = m2n.rows (); \
  93.       int m2_nc = m2n.cols (); \
  94.       if (m1_nr == m2_nr && m1_nc == m2_nc) \
  95.     { \
  96.       if (m1_nr == 0 && m1_nc == 0) \
  97.         return two_empty_result; \
  98.       else \
  99.         { \
  100.           BOOL_OP2 (m1n) \
  101.           BOOL_OP3 (test) \
  102.         } \
  103.     } \
  104.       else \
  105.     { \
  106.       if ((m1_nr == 0 && m1_nc == 0) || (m2_nr == 0 && m2_nc == 0)) \
  107.         return one_empty_result; \
  108.       else \
  109.         { \
  110.           gripe_nonconformant ("operator " op, m1_nr, m1_nc, \
  111.                    m2_nr, m2_nc); \
  112.           return Matrix (); \
  113.         } \
  114.     } \
  115.     } \
  116.   while (0)
  117.  
  118. #define CAST_BINOP_ARGS(t1, t2) \
  119.   t1 v1 = DYNAMIC_CAST (t1, a1); \
  120.   t2 v2 = DYNAMIC_CAST (t2, a2);
  121.  
  122. #define CAST_CONV_ARG(t) \
  123.   t v = DYNAMIC_CAST (t, a);
  124.  
  125. #endif
  126.  
  127. /*
  128. ;;; Local Variables: ***
  129. ;;; mode: C++ ***
  130. ;;; End: ***
  131. */
  132.